package cn.wolfcode.wms.service.impl;

import cn.wolfcode.wms.domain.Department;
import cn.wolfcode.wms.mapper.DepartmentMapper;
import cn.wolfcode.wms.qo.QueryObject;
import cn.wolfcode.wms.service.IDepartmentService;
import cn.wolfcode.wms.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public void saveOrUpdate(Department entity) {
        if (entity.getId() != null) {
            departmentMapper.updateByPrimaryKey(entity);
        } else {
            departmentMapper.insert(entity);
        }
    }

    @Override
    public void delete(Long id) {
        if (id != null) {

            departmentMapper.deleteByPrimaryKey(id);
        }
    }

    @Override
    public Department get(Long id) {

            Department entity = departmentMapper.selectByPrimaryKey(id);
        return entity;

    }

    @Override
    public List<Department> selectall() {
        List<Department> depts = departmentMapper.selectAll();
        return depts;
    }

    @Override
    public PageResult queryForList(QueryObject qo) {
        int rows = departmentMapper.rows(qo);
        if (rows == 0) {
            return PageResult.EMPTY_RESULT;

        }
        PageResult result = new PageResult(qo.getCurrentPage(), qo.getPageSize(), rows, departmentMapper.queryForList(qo));
        System.out.println(66);
        return result;

    }
}
